#define _CRT_SECURE_NO_WARNINGS 1 

#include <iostream>
#include <vector>
using namespace std;

class Solution
{
public:
    int findPoisonedDuration(vector<int>& timeSeries, int duration)
    {
        int ret = 0;
        for (int i = 0; i < timeSeries.size() - 1; i++)
        {
            int x = timeSeries[i + 1] - timeSeries[i];
            if (x >= duration)
            {
                ret += duration;
            }
            else if (x < duration)
            {
                ret += x;
            }
        }
        return ret += duration;
    }
};

int main()
{
    vector<int> timeSeries;
    Solution sol;

    timeSeries.push_back(1);
    timeSeries.push_back(2);
    timeSeries.push_back(5);
    timeSeries.push_back(4);
    timeSeries.push_back(10);
    timeSeries.push_back(16);

    int ret = sol.findPoisonedDuration(timeSeries, 3);

    cout << ret << endl;
    return 0;
}